import tkinter as tk
from tkinter import ttk


class Calculator:
    def __init__(self, master):
        self.master = master
        self.master.title("Simple Calculator")
        self.style = ttk.Style()
        self.style.configure('TButton', font=('Arial', 14), padding=10)
        self.style.configure('TEntry', font=('Arial', 14), padding=10)
        self.display = ttk.Entry(self.master, width=20, style='TEntry')
        self.display.grid(row=0, column=0, columnspan=4, pady=10)
        self.create_buttons()

    def create_buttons(self):
        buttons = [
            ('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3),
            ('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3),
            ('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3),
            ('C', 4, 0), ('0', 4, 1), ('=', 4, 2), ('+', 4, 3)
        ]

        for (text, row, column) in buttons:
            button = ttk.Button(self.master, text=text, style='TButton')
            button.grid(row=row, column=column, padx=5, pady=5, ipadx=10, ipady=10)
            button.bind('<Button-1>', self.button_click)

    def button_click(self, event):
        text = event.widget.cget("text")
        if text == '=':
            try:
                result = eval(self.display.get())
                self.display.delete(0, tk.END)
                self.display.insert(tk.END, str(result))
            except:
                self.display.delete(0, tk.END)
                self.display.insert(tk.END, 'Error')
        elif text == 'C':
            self.display.delete(0, tk.END)
        else:
            self.display.insert(tk.END, text)


if __name__ == "__main__":
    root = tk.Tk()
    calculator = Calculator(root)
    root.mainloop()
